// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.ai.states;

import java.util.HashMap;
import zombie.ai.State;
import zombie.audio.parameters.ParameterZombieState;
import zombie.characters.IsoGameCharacter;
import zombie.characters.IsoZombie;
import zombie.core.skinnedmodel.advancedanimation.AnimEvent;
import zombie.network.GameClient;
import zombie.util.StringUtils;

public final class ZombieGetUpState extends State {
    private static final ZombieGetUpState _instance = new ZombieGetUpState();
    static final Integer PARAM_STANDING = 1;
    static final Integer PARAM_PREV_STATE = 2;

    public static ZombieGetUpState instance() {
        return _instance;
    }

    @Override
    public void enter(IsoGameCharacter owner) {
        IsoZombie isoZombie = (IsoZombie)owner;
        HashMap hashMap = owner.getStateMachineParams(this);
        hashMap.put(PARAM_STANDING, Boolean.FALSE);
        State state = owner.getStateMachine().getPrevious();
        if (state == ZombieGetUpFromCrawlState.instance()) {
            state = (State)owner.getStateMachineParams(ZombieGetUpFromCrawlState.instance()).get(1);
        }

        hashMap.put(PARAM_PREV_STATE, state);
        isoZombie.parameterZombieState.setState(ParameterZombieState.State.GettingUp);
        if (GameClient.bClient) {
            owner.setKnockedDown(false);
        }
    }

    @Override
    public void execute(IsoGameCharacter owner) {
        HashMap hashMap = owner.getStateMachineParams(this);
        boolean _boolean = hashMap.get(PARAM_STANDING) == Boolean.TRUE;
        owner.setOnFloor(!_boolean);
        ((IsoZombie)owner).setKnockedDown(!_boolean);
    }

    @Override
    public void exit(IsoGameCharacter owner) {
        HashMap hashMap = owner.getStateMachineParams(this);
        IsoZombie isoZombie = (IsoZombie)owner;
        owner.setCollidable(true);
        owner.clearVariable("SprinterTripped");
        owner.clearVariable("ShouldStandUp");
        if (StringUtils.isNullOrEmpty(owner.getHitReaction())) {
            isoZombie.setSitAgainstWall(false);
        }

        isoZombie.setKnockedDown(false);
        isoZombie.AllowRepathDelay = 0.0F;
        if (hashMap.get(PARAM_PREV_STATE) == PathFindState.instance()) {
            if (owner.getPathFindBehavior2().getTargetChar() == null) {
                owner.setVariable("bPathfind", true);
                owner.setVariable("bMoving", false);
            } else if (isoZombie.isTargetLocationKnown()) {
                owner.pathToCharacter(owner.getPathFindBehavior2().getTargetChar());
            } else if (isoZombie.LastTargetSeenX != -1) {
                owner.pathToLocation(isoZombie.LastTargetSeenX, isoZombie.LastTargetSeenY, isoZombie.LastTargetSeenZ);
            }
        } else if (hashMap.get(PARAM_PREV_STATE) == WalkTowardState.instance()) {
            owner.setVariable("bPathFind", false);
            owner.setVariable("bMoving", true);
        }
    }

    @Override
    public void animEvent(IsoGameCharacter owner, AnimEvent event) {
        HashMap hashMap = owner.getStateMachineParams(this);
        IsoZombie isoZombie = (IsoZombie)owner;
        if (event.m_EventName.equalsIgnoreCase("IsAlmostUp")) {
            hashMap.put(PARAM_STANDING, Boolean.TRUE);
        }
    }
}
